<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
  <#include "/common/elibs.html">
</head><body><div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="${request.contextPath}/index">首页</a>
        <a href="#">项目管理</a>
        <a>
          <cite>列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
      <i class="layui-icon" style="line-height:30px">ဂ</i></a>
  </div><div class="x-body">
    <div class="layui-row">
      <table class="layui-hide" id="test" lay-filter="test"></table>
      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <button class="layui-btn layui-btn-sm" lay-event="add" id="add" onclick="showMsg()">
            <i class="layui-icon"></i>创建项目</button>
        </div>
      </script>
      <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
      </script>
    </div></div><script>
  isToken();
      layui.use('table', function(){
          var table = layui.table;
          table.render({
              elem: '#test'
              ,url: path+'/pc/project/getProjectList'
            ,headers:{'X-USER-TOKEN':localStorage.getItem("token")}
              ,toolbar: '#toolbarDemo'
              ,title: '项目数据表'
              ,cols: [[
                  {type: 'checkbox', fixed: 'left'}
                  ,{field:'idProAdmin',type:'numbers', title:'ID', width:80, fixed: 'left' }
              ,{field:'customerName', title:'客户名称', width:200 }
              ,{field:'customerPhone', title:'联系电话', width:150}
              ,{field:'electricTotalCapacity', title:'报装容量'}
              ,{field:'status', title:'项目进度',
                templet: function (red) {
                  if (red.status == '0') {
                    return "停用";
                  } else if (red.status == '1') {
                    return "初始状态";
                  } else if (red.status == '21') {
                    return "现场勘查";
                  } else if (red.status == '22') {
                    return "制定供电方案";
                  } else if (red.status == '23') {
                    return "图纸审查";
                  } else if (red.status == '31') {
                    return "间隔审批";
                  } else if (red.status == '32') {
                    return "申请双重编号";
                  } else if (red.status == '33') {
                    return "下达双重编号";
                  } else if (red.status == '34') {
                    return "告知";
                  } else if (red.status == '35') {
                    return "停电接火";
                  } else if (red.status == '36') {
                    return "保护定值报送";
                  } else if (red.status == '37') {
                    return "中间检查";
                  } else if (red.status == '38') {
                    return "竣工资料收集";
                  } else if (red.status == '41') {
                    return "竣工验收";
                  } else if (red.status == '42') {
                    return "复验";
                  } else if (red.status == '43') {
                    return "送电启动";
                  } else if (red.status == '44') {
                    return "用户评价工作";
                  } else if (red.status == '45') {
                    return "资料归档";
                  }else if (red.status == '100') {
                    return "项目已完成";
                  }else{
                    return "未知状态";
                  }
                }}
              ,{field:'transmissionStatus', title:'送电状态',
                templet: function (red) {
                 if (red.transmissionStatus == '0') {
                    return "未送电";
                  } else if (red.transmissionStatus == '1') {
                    return "送电成功";
                  } else{
                    return "未知状态";
                  }
                }}
              ,{field:'powerTransmissionTime', title:'送电时间', width:220}
              ,{field: 'right', title: '操作',
                templet: function (d) {
                  var html = '';
                  if(d.status === 1 ){//项目状态为当前进度 并且提交状态小于3给予添加操作
                    html += '<a class="layui-btn layui-bt0n-primary  layui-btn-xs" lay-event="edit">编辑</a>';
                  }else {
                    html += '<a class="layui-btn layui-bt0n-primary  layui-btn-xs" lay-event="edit">查看</a>';
                  }
                  html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                  return html;
                }}
          ]]
            ,request: {
              pageName: 'currentPage' //页码的参数名称，默认：page
            }
            , parseData: function (res) { //res 即为原始返回的数据
              return {
                "code": res.code, //解析接口状态
                "msg": res.message, //解析提示文本
                "count": res.data.totalResult, //解析数据长度
                "data": res.data.data //解析数据列表
              }
            }
            , page: true
            , limit: 10
            , id: 'testReload'
      });
          var $ = layui.$, active = {reload: function(){
                  var tcaParentsId = $("#tcaParentsId").val();
                  var tcaName =  $("#tcaName").val();
                  if(tcaParentsId == "" && tcaName == ""){
                      return;
                  }
                  table.reload('testReload',{
                      where: { //设定异步数据接口的额外参数，任意设
                          tcaParentsId: tcaParentsId
                          ,tcaName: tcaName
                      }
                      ,page: {
                          curr: 1 //重新从第 1 页开始
                      }
                  }); //重载表格
           }}
          $('#sreach').on('click', function(){
              var type = $(this).data('type');
              active[type] ? active[type].call(this) : '';
          });//监听行工具事件
          table.on('tool(test)', function(obj){
              var data = obj.data;
              //console.log(obj)
              if(obj.event === 'del'){
                  layer.confirm('真的删除行么', function(index){
                      var params = {
                        idProAdmin : data.idProAdmin
                      }
                      console.log(params);
                      if(true){
                          $.ajax({
                              url: path +'/pc/project/deleteProject',
                              type: 'post',
                              data: params,
                              success: function(datas) {
                                if (datas.code != 0) {
                                  layer.open({
                                    title: '提示信息'
                                    , content: datas.message
                                  });
                                } else {
                                  $(".layui-form-checked").not('.header').parents('tr').remove();
                                  layer.msg('删除成功', {icon: 1});
                                  obj.del();
                                  layer.close(index);
                                  console.log("success !");
                                }8
                              },
                              traditional:true
                          });
                      }
                  });
              } else if(obj.event === 'edit'){
                  window.location.href = '${request.contextPath}/modules/project/edit.html?id='+obj.data.idProAdmin;
              }
          });});
      layui.use('layer', function(){
          var layer = layui.layer;
          $(document).on('click','#add',function(){
              if(true){ //查看
                  window.location.href=path+"/modules/project/add.html";
              }
          });
      });

      function showMsg() {
        window.location.href=path+"/modules/project/add.html";
      }
    </script></body></html>